/* 
 数组按关键字合并同值
 cover:
	forward 向后覆盖
	backward 向前覆盖
 */
function uniqueArrayObject(array, key, cover = 'forward') {
	if (!Array.isArray(array)) return null;
	
	const uniqueMap = array[cover === 'backward' ? 'reduce' : 'reduceRight']((last, next) => {
			last[next[key]] = next;
			return last;
		}, {})
	
	return Object.values(uniqueMap);
}

export {
	uniqueArrayObject
}